#!/bin/bash 

source ./fuck-schoolnet.conf

# Set ip address
ip addr add $ip_address/$subnetmask dev $device
ip link set dev $device up

# Open route forward
echo "1" > /proc/sys/net/ipv4/ip_forward

# Loading gre module
modprobe ip_gre

# Configuring gre tunnel
ip tunnel add $gre_tunnel mode gre local $gre_local remote $gre_remote ttl 255
ip addr add $gre_address dev $gre_tunnel peer $gre_peer
ip link set dev $gre_tunnel up

# Set route/gateway
ip route add default via $gateway
ip route add $saddr via $gre_peer

# SNAT
nft add table nat
nft 'add chain nat postrouting { type nat hook postrouting priority 100 ; }'
nft add rule nat postrouting ip saddr $saddr oif $device snat to $ip_address
nft add rule nat postrouting ip saddr $saddr1 oif $device snat to $ip_address

